<?php   
class Repairs extends Model {

    /*
     * EXPERIMENTAL
     */
    function entity2array($entity, $recursionDepth = 2) {
        $result = array();
        $class = new ReflectionClass(get_class($entity));
        foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
            $methodName = $method->name;
            if (strpos($methodName, "get") === 0 && strlen($methodName) > 3) {
                $propertyName = lcfirst(substr($methodName, 3));
                $value = $method->invoke($entity);

                if (is_object($value)) {
                    if ($recursionDepth > 0) {
                        $result[$propertyName] = $this->entity2array($value, $recursionDepth - 1);
                    } else {
                        $result[$propertyName] = "***";     //stop recursion
                    }
                } else {
                    $result[$propertyName] = $value;
                }
            }
        }
        return $result;
    }


    
    
    /*
     * Процессор всех видов ремонтных работ
     */
    function repairsKindProcess($params = array()){

        if(count($params) == 0){

            $tmp = $this->dismount($this->registry->request);

            if(isset($tmp['get']['page'])) $params['offset'] = $tmp['get']['page'];
            if(isset($tmp['post']['page'])) $params['offset'] = $tmp['post']['page'];

            if(isset($tmp['get']['rows'])) $params['limit'] = $tmp['get']['rows'];
            if(isset($tmp['post']['rows'])) $params['limit'] = $tmp['post']['rows'];

            if(isset($tmp['get']['sidx'])) $params['order_by_column'] = $tmp['get']['sidx'];
            if(isset($tmp['post']['sidx'])) $params['order_by_column'] = $tmp['post']['sidx'];

            if(isset($tmp['get']['sord'])) $params['order'] = $tmp['get']['sord'];
            if(isset($tmp['post']['sord'])) $params['order'] = $tmp['post']['sord'];

            unset($tmp);
        }

        ///EXAMPLE
        ///$search = (string) $this->registry->request->getParameter('_search');

        # count
        $whole_count = 0;

        $PhotoModel = new PhotoModel('vmodul_id',$this -> registry -> virtual_modul_id );
        $data = $PhotoModel -> getData();

        if(is_array($data)) $whole_count = count($data);

        unset($PhotoModel);
        unset($data);

        //$PhotoModel = new PhotoModel('vmodul_id',Registry::getInstance() -> virtual_modul_id );
        $PhotoModel = new PhotoModel('vmodul_id',$this -> registry -> virtual_modul_id, $params );

        $data = $PhotoModel -> getData();
        
        if( is_array($data) ){
            if(count($data) > 0){
                $this->dataPostProcess($data);
                //$this->setData($data);
            }
        }

        $photos['whole_count'] = $whole_count;
        $photos['count'] = is_array($data) ?  count($data) : 0;
        $photos['data']  = $data;

        return $photos;
        
    }
    
    private function dataPostProcess(&$data){
        for($i = 0; $i < count($data); $i++){
            $link = $data[$i]['link'];
            $data[$i]['link'] =    "$link";
            $data[$i]['link_sm'] =  "sm_$link";
        }

        /*
        if($this->registry -> virtual_modul_index == 'Kitchen'){
            for($i = 0; $i < count($data); $i++){
                $link = $data[$i]['link'];
                $data[$i]['link'] = "../Image/" . strtolower($this->registry -> virtual_modul_index) . "/$link";
                $data[$i]['link_sm'] = "../Image/" . strtolower($this->registry -> virtual_modul_index) . "/sm_$link";
            }
        } elseif($this->registry -> virtual_modul_index == 'Hall'){
            for($i = 0; $i < count($data); $i++){
                $link = $data[$i]['link'];
                $data[$i]['link'] = "../Image/" . strtolower($this->registry -> virtual_modul_index) . "/$link";
                $data[$i]['link_sm'] = "../Image/" . strtolower($this->registry -> virtual_modul_index) . "/sm_$link";
            }
        }
        */
    }
     
    
}

    
 
?>